from django.db import models
from users.models import UserProfile
from devices.models import Device,DeviceStatus
# Create your models here.


class Operator(models.Model):
    name = models.CharField(max_length=40,verbose_name="姓名")
    employee_id= models.CharField(max_length=5,verbose_name="工号",unique=True)
    password = models.CharField(max_length=4,verbose_name="密码")
    has_enabled= models.BooleanField(default=True,verbose_name="在职？")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name="操作员设置"
        verbose_name_plural=verbose_name


class OptionLog(models.Model):
    operator = models.ForeignKey(Operator,related_name="rel_log_operator",verbose_name="操作员")
    device = models.ForeignKey(Device,related_name="rel_log_device",verbose_name="设备编号")
    create_time = models.DateTimeField(auto_now_add=True,verbose_name="巡检时间",editable=True)
    devicestatus = models.ForeignKey(DeviceStatus,null=True,blank=True,verbose_name="设备状态",related_name="rel_status")

    def __str__(self):
        return self.device.name

    class Meta:
        verbose_name="巡检记录"
        verbose_name_plural=verbose_name
        unique_together=("operator",'device','create_time')
